﻿using AutoMapper;
using B.S.DataBase.Domain;
using B.S.DataBase.ErrorCode;
using B.S.DataBase.Infrastructure;
using B.S.DataBase.Read.API.Application.Commands.GetSelectProduct;
using MediatR;

namespace B.S.DataBase.Read.API.Application.Handlers.GetSelectProductHandler
{
    public class GetSelectProductTypeHandler : IRequestHandler<GetSelectProductType, APIResult<List<ProductType>>>
    {
        private readonly IBaseRepository<ProductType> protypeRepository;
        private readonly IMapper mapper;

        public GetSelectProductTypeHandler(IBaseRepository<ProductType> protypeRepository, IMapper mapper)
        {
            this.protypeRepository = protypeRepository;
            this.mapper = mapper;
        }

        public Task<APIResult<List<ProductType>>> Handle(GetSelectProductType request, CancellationToken cancellationToken)
        {
            APIResult<List<ProductType>> result = new APIResult<List<ProductType>>();

            var entity = mapper.Map<ProductType>(request);

            var dto = protypeRepository.GetAllAsync().ToList();

            result.Code = APIEnums.Success;
            result.Meg = "商品类型查询成功";
            result.Data = dto;


            return Task.FromResult(result);
        }
    }
}
